import {
    promisic
} from "./util.js";

/**
 * type=1 title+content
 * type=2 title
 * type=3 content
 */
const showModal = function(title, type = 1, content = "", showCancel = true) {
    const promise = new Promise((resolve, reject) => {
        if (type == 1) {
            wx.showModal({
                title: title,
                content: content,
                showCancel: showCancel,
                success: res => {
                    res.confirm ? resolve(true) : resolve(false)
                }
            })
            return
        }

        if (type == 2) {
            wx.showModal({
                title: title,
                showCancel: showCancel,
                success: res => {
                    res.confirm ? resolve(true) : resolve(false)
                }
            })
            return
        }

        if (type == 3) {
            wx.showModal({
                content: title,
                showCancel: showCancel,
                success: res => {
                    res.confirm ? resolve(true) : resolve(false)
                }
            })

        }

    })
    return promise;
}



const showModal1 = function(title, showCancel) {
    let promise = new Promise((resolve, reject) => {
        wx.showModal({
            content: title,
            showCancel: showCancel,
            success: res => {
                res.confirm ? resolve(true) : resolve(false)
            }
        })
    })
}
const showToast = function(title) {
    wx.showToast({
        title: title,
        icon: 'none',
        duration: 2000,
    })
}

export {
    showToast,
    showModal
}